# -*- coding: utf-8 -*-

import unittest

from utils.Sending import mail
# from testsuites.suite_demo import suite
from XTestRunner import HTMLTestRunner
import os

if __name__ == '__main__':

    # 确保 reports 目录存在（注意路径是 ./reports/）
    os.makedirs('./reports', exist_ok=True)

    # 定义报告路径（统一使用 ./reports/result.html）
    filename = './reports/result.html'

    suite = unittest.defaultTestLoader.discover(start_dir='./testcases', pattern='test*.py')
    # 以二进制写入模式打开文件
    with open(filename, 'wb') as f:
        runner = HTMLTestRunner(
            stream=f,
            title='测试报告',
            description='酒仙网自动化测试',
            tester='柏阳辉'
        )
        runner.run(suite)
        contents=['./reports/result.html','./logs/2025-06-03.txt']
        mail(user='2652494214@qq.com',
             password='dhezfeypojmvdhji',
             host='smtp.qq.com',
             to='2652494214@qq.com',
             subject='酒仙网搜索并下单业务',
             contents=contents)
